home *** CD-ROM | disk | FTP | other *** search
- ; RWSUB2 - disk read/write subroutine for compiled BASIC
- ; Copyright 1983 Data Base Decisions
- ;
- ; Note: This routine requires DOS 2.00 or later!
- ;
- ; CALL RWSUB2(FIL$,FUNC%,SBYTELO%,SBYTEHI%,NOBYTES%,DTASEG%,RETCODE%)
- ; FIL$ is the file name in ASCIIZ format
- ; FUNC% indicates reading (=0), writing (=1), or creating (and writing =2)
- ; SBYTELO% is the low part of the starting byte
- ; SBYTEHI% is the high part of the starting byte (HI*65536+LO)
- ; NOBYTES% is the number of bytes to be read/written
- ; DTASEG% is the segment to be read into or written from
- ; RETCODE% is an error return code (non-zero if an error occurred)
-
- skip equ 2 ; 2 for compiled, 1 for interpretive
-
- cseg segment para public 'code'
- public rwsub2
- rwsub2 proc far
- assume cs:cseg,ds:nothing,ss:nothing,es:nothing
-
- push bp
- mov bp,sp
-
- ; open the file
- mov si,[bp+18] ; point to FIL$
- add si,skip
- mov dx,[si] ; point to file name
- mov si,[bp+16] ; point to FUNC%
- mov al,[si] ; get access code in al
- mov ah,3dh
- cmp al,2 ; create?
- jnz p010 ; no
- dec ah
- mov cx,0 ; clear attributes
- p010: int 21h ; open the file
- jc p030 ; error?
-
- ; set the file pointer
- mov bx,ax ; get the handle
- mov si,[bp+12] ; point to SBYTEHI%
- mov cx,[si] ; put it in cx
- mov si,[bp+14] ; point to SBYTELO%
- mov dx,[si] ; put it in dx
- mov ah,42h ; move file read/write pointer
- mov al,0 ; method 0 - offset from beginning of file
- int 21h ; position in the file
- jc p030 ; error?
-
- ; read/write the file
- mov si,[bp+10] ; point to NOBYTES%
- mov cx,[si] ; number of bytes to read/write
- mov si,[bp+16] ; point to FUNC%
- mov ah,[si] ; 0 for read, 1 for write
- cmp ah,2 ; create?
- jnz p020 ; no
- dec ah ; yes - make it a write
- p020: add ah,3fh ; setup interrupt function
- push ds
- mov si,[bp+8] ; point to DTASEG%
- mov dx,[si]
- mov ds,dx ; now in ds
- xor dx,dx ; ds:dx contains DTA
- int 21h ; read/write the file
- pop ds ; get orig ds
- jc p030 ; error?
- mov si,[bp+10] ; point to NOBYTES%
- mov [si],ax ; save bytes read/written
-
- ; close the file
- mov ah,3eh
- int 21h ; close the file
- jnc p040 ; no error
-
- p030: ; error handler
- mov si,[bp+6] ; point to RETCODE%
- mov [si],ax ; save the error
-
- p040: ; return to caller
- pop bp
- ret 14
-
- rwsub2 endp
- cseg ends
- end
-